package com.example.springaiollama.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/examples")
@CrossOrigin(origins = "*")
public class ExampleController {

    /**
     * 提供 Function Calling 的使用示例
     */
    @GetMapping("/function-calling")
    public ResponseEntity<Map<String, Object>> getFunctionCallingExamples() {
        return ResponseEntity.ok(Map.of(
            "success", true,
            "examples", Map.of(
                "time_query", Map.of(
                    "description", "查询当前时间",
                    "request", Map.of(
                        "url", "POST /api/ai/chat-with-function-calling",
                        "body", Map.of("message", "现在几点了？")
                    ),
                    "expected_response", "当前时间: 2024-01-15 14:30:25"
                ),
                "weather_query", Map.of(
                    "description", "查询天气信息",
                    "request", Map.of(
                        "url", "POST /api/ai/chat-with-function-calling",
                        "body", Map.of("message", "北京今天天气怎么样？")
                    ),
                    "expected_response", "天气信息: 晴天，温度 25°C，湿度 60%"
                ),
                "calculation", Map.of(
                    "description", "数学计算",
                    "request", Map.of(
                        "url", "POST /api/ai/chat-with-function-calling",
                        "body", Map.of("message", "请计算 15 + 27 的结果")
                    ),
                    "expected_response", "计算结果: 42"
                ),
                "translation", Map.of(
                    "description", "文本翻译",
                    "request", Map.of(
                        "url", "POST /api/ai/chat-with-function-calling",
                        "body", Map.of("message", "请把 'Hello World' 翻译成中文")
                    ),
                    "expected_response", "翻译结果: Hello World (中文翻译)"
                ),
                "complex_query", Map.of(
                    "description", "复杂查询（带系统提示词）",
                    "request", Map.of(
                        "url", "POST /api/ai/chat-with-function-calling-and-system",
                        "body", Map.of(
                            "message", "请告诉我现在的时间，然后查询北京的天气",
                            "systemPrompt", "你是一个智能助手，可以使用各种工具来帮助用户"
                        )
                    ),
                    "expected_response", "包含时间和天气信息的综合回答"
                )
            ),
            "available_endpoints", new String[]{
                "GET /api/ai/tools - 获取可用工具列表",
                "POST /api/ai/chat-with-function-calling - 基础函数调用聊天",
                "POST /api/ai/chat-with-function-calling-and-system - 带系统提示词的函数调用聊天"
            },
            "timestamp", System.currentTimeMillis()
        ));
    }
} 